<?php
$this->headTitle($this->translator('customer_edit_info_title_page'));
$this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js');
?>

<?php if($this->isAllowAction):?>
<?php
    $user = $this->user;
    $customer = $this->customer;
?>
<div class="t_bizprofile_register grid_12">
    <form method="post" action="" id="checkOutForm">
        <div class="grid_8 alpha">
            <!--Billing-->
            <div class="icon_title"><span><?php echo $this->translator('checkout_billing_address', 'shoppingcart'); ?></span></div>
            <div class="flash_message" style="float: left;"><?php echo $this->flashMessenger(); ?></div>
            <div class="clearfix">
                <label><?php echo $this->translator('checkout_fullname', 'shoppingcart'); ?>:</label>
                <font style="color:red; padding-left: 5px;">(*)</font>
                <input value="<?php echo isset($user->full_name)?$user->full_name:null;?>" type="text" id="full_name" name="full_name" style="width: 200px" />
            </div>

            <div class="clearfix">
                <label><?php echo $this->translator('checkout_email', 'shoppingcart'); ?>:</label>
                <input <?php if($this->user):?>disabled<?php endif;?> value="<?php echo isset($user->email)?$user->email:null;?>" type="text" id="email" name="email" style="width: 200px" />                
            </div>

            <div class="clearfix">
                <label><?php echo $this->translator('checkout_full_address', 'shoppingcart'); ?>:</label>
                <font style="color:red; padding-left: 5px;">(*)</font>
                <input value="<?php echo isset($customer->customer_address)?$customer->customer_address:null;?>" type="text" id="address" name="address" style="width: 200px" />
            </div>

            <div class="clearfix">
                <label><?php echo $this->translator('checkout_city', 'shoppingcart'); ?>:</label>
                <font style="color:red; padding-left: 5px;">(*)</font>
                <input value="<?php echo isset($customer->customer_city)?$customer->customer_city:null;?>" type="text" id="city" name="city" style="width: 200px" />
            </div>

            <div class="clearfix">
                <label><?php echo $this->translator('checkout_tel', 'shoppingcart'); ?>:</label>
                <font style="color:red; padding-left: 5px;">(*)</font>
                <input value="<?php echo isset($customer->customer_tel)?$customer->customer_tel:null;?>" type="text" id="tel" name="tel" style="width: 200px" />
            </div>

            <!--Shipping-->
            <div class="icon_title"><span><?php echo $this->translator('checkout_shipping_address', 'shoppingcart'); ?></span></div>

            <!--<div class="clearfix">
                <label>&nbsp;</label>
                <input type="checkbox" id="same_address" name="same_address"/>&nbsp;
                <?php echo $this->translator('same_info', 'shoppingcart');?>
            </div>-->
            <div class="grid_8 alpha">
                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_fullname', 'shoppingcart'); ?>:</label>
                    <font style="color:red; padding-left: 5px;">(*)</font>
                    <input value="<?php echo isset($customer->shipping_name)?$customer->shipping_name:null;?>" type="text" id="shipping_name" name="shipping_name" style="width: 200px" />
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_email', 'shoppingcart'); ?>:</label>
                    <font style="color:red; padding-left: 5px;">(*)</font>
                    <input value="<?php echo isset($customer->shipping_email)?$customer->shipping_email:null;?>" type="text" id="shipping_email" name="shipping_email" style="width: 200px" />
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_full_address', 'shoppingcart'); ?>:</label>
                    <font style="color:red; padding-left: 5px;">(*)</font>
                    <input value="<?php echo isset($customer->shipping_address)?$customer->shipping_address:null;?>" type="text" id="shipping_address" name="shipping_address" style="width: 200px" />
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_city', 'shoppingcart'); ?>:</label>
                    <font style="color:red; padding-left: 5px;">(*)</font>
                    <input value="<?php echo isset($customer->shipping_city)?$customer->shipping_city:null;?>" type="text" id="shipping_city" name="shipping_city" style="width: 200px" />
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_tel', 'shoppingcart'); ?>:</label>
                    <font style="color:red; padding-left: 5px;">(*)</font>
                    <input value="<?php echo isset($customer->shipping_tel)?$customer->shipping_tel:null;?>" type="text" id="shipping_tel" name="shipping_tel" style="width: 200px" />
                </div>
                <?php if($this->flag):?>
                <div class="clearfix">
                    <label>&nbsp;</label>
                    <?php echo $this->translator('checkout_warning_change_shipping_info', 'shoppingcart');?>
                </div>
                <?php endif;?>
            </div>
            <div class="clearfix"></div>
            <div class="clearfix">
                <label>&nbsp;</label>
                <button type="submit"><span><?php echo $this->translator('customer_save_button'); ?></span></button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
$(document).ready(function() {

    /**
    * same value
    */
    $('#same_address').click(function(){
        bool = $(this).attr('checked');
        if(true == bool){
            full_name = $('#full_name').val();
            $('#shipping_name').attr('value', full_name);

            email = $('#email').val();
            $('#shipping_email').attr('value', email);

            address = $('#address').val();
            $('#shipping_address').attr('value', address);

            city = $('#city').val();
            $('#shipping_city').attr('value', city);

            tel = $('#tel').val();
            $('#shipping_tel').attr('value', tel);
        }
        else{
            $('#shipping_name').attr('value', '');
            $('#shipping_email').attr('value', '');
            $('#shipping_address').attr('value', '');
            $('#shipping_city').attr('value', '');
            $('#shipping_tel').attr('value', '');
        }
    })

    /**
    * Validate form
    */
    $('#checkOutForm').validate({
        rules: {
            full_name: {
                required: true
            },
            email: {
                required: true,
                email: true,
                remote: '<?php echo (!$this->user)?$this->url(array('check_type' => 'email'), 'bizprofile_user_check'):false ;?>'
            },
            address: {
                required: true
            },
            city: {
                required: true
            },
            tel: {
                required: true
            },
            shipping_name: {
                required: true
            },
            shipping_email: {
                required: true,
                email: true,
            },
            shipping_address: {
                required: true
            },
            shipping_city: {
                required: true
            },
            shipping_tel: {
                required: true
            },
            cart_charter:{
                required: true
            }
        },
        messages: {
            full_name: {
                required: "<?php echo $this->translator('checkout_fullname_required', 'shoppingcart'); ?>"
            },
            email: {
                required: "<?php echo $this->translator('checkout_email_required', 'shoppingcart'); ?>",
                email: "<?php echo $this->translator('checkout_email_invalid', 'shoppingcart'); ?>",
                remote: "<?php echo $this->translator('checkout_email_exists', 'shoppingcart'); ?>"
            },
            address: {
                required: "<?php echo $this->translator('checkout_address_required', 'shoppingcart'); ?>"
            },
            city: {
                required: "<?php echo $this->translator('checkout_city_required', 'shoppingcart'); ?>"
            },
            tel: {
                required: "<?php echo $this->translator('checkout_tel_required', 'shoppingcart'); ?>"
            },
            shipping_name: {
                required: "<?php echo $this->translator('checkout_fullname_required', 'shoppingcart'); ?>"
            },
            shipping_email: {
                required: "<?php echo $this->translator('checkout_email_required', 'shoppingcart'); ?>",
                email: "<?php echo $this->translator('checkout_email_invalid', 'shoppingcart'); ?>",
            },
            shipping_address: {
                required: "<?php echo $this->translator('checkout_address_required', 'shoppingcart'); ?>"
            },
            shipping_city: {
                required: "<?php echo $this->translator('checkout_city_required', 'shoppingcart'); ?>"
            },
            shipping_tel: {
                required: "<?php echo $this->translator('checkout_tel_required', 'shoppingcart'); ?>"
            },
            cart_charter: {
                required: "<?php echo $this->translator('checkout_accept_required', 'shoppingcart'); ?>"
            }
        },
        errorPlacement: function(error, element) {
            if(element.attr('id') == 'cart_charter') {
                error.appendTo('#invalid_' + element.attr('id'));
            }else{
                error.insertAfter(element);
            }
        }
    });
});
</script>
<?php else:?>
    <div class="grid_12"><?php echo $this->translator('customer_no_permission');?></div>
<?php endif;?>